package k4_thread.demo04;

public class ThreadThree {

    /**
     * 两个同步锁的非静态方法，创建两个对象，分别创建两个线程，分别在两个线程中进行调用
     * 锁的对象是两个对象，互不影响
     * @param args
     */
    public static void main(String[] args) {

        System.out.println("=====start=====");

        Phone3 phone1 = new Phone3();
        Phone3 phone2 = new Phone3();

        //第一个线程，表示发送短信
        new Thread(()->phone1.sendMessage()).start();
        //第二个线程，表示打电话
        new Thread(()->phone2.callPhone()).start();
    }
}

class Phone3{

    public synchronized void sendMessage(){
        try {
            Thread.sleep(3000);
            System.out.println("=====发短信=====");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public synchronized void callPhone(){
        System.out.println("=====打电话=====");
    }

}
